package com.jackrain.nea.omslocal.task;

import com.jackrain.nea.config.PropertiesConf;
import com.jackrain.nea.omslocal.service.OrderStatusQueryService;
import com.jackrain.nea.omslocal.service.QiMenEventProduceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author ：wcy
 * @date ：Created in 16:22 2018/8/9
 * description ：自动发送奇门事件数据(全渠道)
 */
@Component
@Slf4j
public class AutoQiMenEventProduce {
    private final QiMenEventProduceService qiMenEventProduceService;
    private final PropertiesConf pconf;

    @Autowired
    public AutoQiMenEventProduce(QiMenEventProduceService qiMenEventProduceService, PropertiesConf pconf) {
        this.qiMenEventProduceService = qiMenEventProduceService;
        this.pconf = pconf;
    }

    void getScheduledExecutorSendA() {
        log.debug("AutoMotThreads AutoQiMenEventProduce started !!!");
        Runnable runnable = () -> {
            try {
                qiMenEventProduceService.ordStart();
            } catch (Exception e) {
                e.printStackTrace();
            }
        };
        ScheduledExecutorService service = Executors
                .newSingleThreadScheduledExecutor();
        // 第二个参数为首次执行的延时时间，第三个参数为定时执行的间隔时间
        // 正式 要延迟适当时间,以便时间初始化赋值
        service.scheduleAtFixedRate(runnable, 10, pconf.getPropertyInt("ons.qiMenEventIntervalTime"), TimeUnit.SECONDS);
    }
}
